
var utmObj = require('utm-latlng');
var utm=new utmObj();
var ZoneLetter, ZoneNumber;

function getUTM(point) {
    let data = [[], []];

    point.forEach((item) => {
        let cell = utm.convertLatLngToUtm(item.lat, item.lng, 3)
        
        ZoneLetter = ZoneLetter || cell.ZoneLetter;
        ZoneNumber = ZoneNumber || cell.ZoneNumber;
        data[0].push(cell.Easting);
        data[1].push(cell.Northing);
    })

    return data;
}

function getGPS(point) {
    let data = [];
    let xPoint = point[0];
    let yPoint = point[1];

    for(let i = 0; i < xPoint.length; ++i) {
        let cell = utm.convertUtmToLatLng(xPoint[i], yPoint[i], ZoneNumber, ZoneLetter);
        
        data.push(cell);
    }
    return data;
}

module.exports = {
    getUTM,
    getGPS
}